From 619799ba3bcc8525cc78b98c34e62a34e989f550 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 1 Mar 2016 08:29:31 -0500 Subject: [PATCH] wayland: make deliver_key_event return void deliver_key_event is sometimes called from a timeout handler and sometimes called directly. We currently erroneously return TRUE (G_SOURCE_CONTINUE) in the case where it's called directly, but to no ill effect, since we ignore that return value. In the future, we're going to need to call it directly in other parts of the code where the return value would be relevant and handling TRUE, would require adding redundant code. Instead, this commit just changes the code to always reset the timer manually, and never rely on glib's ability to automatically reset the timer by returning TRUE. This makes the code smaller, too, since there's less special casing required. https://bugzilla.gnome.org/show_bug.cgi?id=757942 --- gdk/wayland/gdkdevice-wayland.c | 45 +++++++++++++-------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 9b085ad35a..9cfe6d9d1b 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -1694,7 +1694,7 @@ stop_key_repeat (GdkWaylandDeviceData *device) } } -static gboolean +static void deliver_key_event (GdkWaylandDeviceData *device, uint32_t time_, uint32_t key, @@ -1705,7 +1705,9 @@ deliver_key_event (GdkWaylandDeviceData *device, struct xkb_keymap *xkb_keymap; GdkKeymap *keymap; xkb_keysym_t sym; - guint delay, interval; + guint delay, interval, timeout; + + stop_key_repeat (device); keymap = device->keymap; xkb_state = _gdk_wayland_keymap_get_xkb_state (keymap); @@ -1739,38 +1741,25 @@ deliver_key_event (GdkWaylandDeviceData *device, event->key.string, event->key.state)); if (!xkb_keymap_key_repeats (xkb_keymap, key)) - return FALSE; + return; if (!get_key_repeat (device, &delay, &interval)) - return FALSE; + return; device->repeat_count++; device->repeat_key = key; if (state == 0) - { - stop_key_repeat (device); - return FALSE; - } + return; + + if (device->repeat_count == 1) + timeout = delay; else - { - switch (device->repeat_count) - { - case 1: - stop_key_repeat (device); - device->repeat_timer = - gdk_threads_add_timeout (delay, keyboard_repeat, device); - g_source_set_name_by_id (device->repeat_timer, "[gtk+] keyboard_repeat"); - return TRUE; - case 2: - device->repeat_timer = - gdk_threads_add_timeout (interval, keyboard_repeat, device); - g_source_set_name_by_id (device->repeat_timer, "[gtk+] keyboard_repeat"); - return FALSE; - default: - return TRUE; - } - } + timeout = interval; + + device->repeat_timer = + gdk_threads_add_timeout (timeout, keyboard_repeat, device); + g_source_set_name_by_id (device->repeat_timer, "[gtk+] keyboard_repeat"); } static gboolean @@ -1778,7 +1767,9 @@ keyboard_repeat (gpointer data) { GdkWaylandDeviceData *device = data; - return deliver_key_event (device, device->time, device->repeat_key, 1); + deliver_key_event (device, device->time, device->repeat_key, 1); + + return G_SOURCE_REMOVE; } static void -- 2.30.2